/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cashmate.struts;

import com.cashmate.hibernate.dao.BorrowerDAO;
import com.cashmate.hibernate.dao.LoanverificationDAO;
import com.cashmate.hibernate.pojo.Loanverification;
import com.opensymphony.xwork2.ActionSupport;
import java.util.ArrayList;
import java.util.List;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author Lee
 */
public class GetLoanapps_AP extends ActionSupport {

    private BorrowerDAO bord = (BorrowerDAO) ServletActionContext.getServletContext().getAttribute("borrowerDAO");
    private LoanverificationDAO lvd = (LoanverificationDAO) ServletActionContext.getServletContext().getAttribute("loanverificationDAO");
    private String[] laapList;
    private List<String> laapList1;

    public String[] getLaapList() {
        return laapList;
    }

    @Action(value = "/get-la-ap", results = {
        @Result(name = "input", location = "/loanapplication.jsp"),
        @Result(name = "success", location = "/loanapplication.jsp"),
        @Result(name = "error", location = "/loanapplication.jsp")
    })
    @Override
    public String execute() {
//        System.out.println("yes");
        laapList1 = new ArrayList<String>();
        List<Loanverification> llaap = null;
        List<Loanverification> llaafnoap = null;

        try {
            llaap = lvd.getAll();
        } catch (Exception e) {
            e.printStackTrace();
        }

        if (llaap != null) {
            llaafnoap = new ArrayList<Loanverification>();
            for (int i = 0; i < llaap.size(); i++) {
                if (!llaap.get(i).getWithap().equals("y")) {
                    llaafnoap.add(llaap.get(i));
//                    System.out.println(llaap.get(i).getLoanverificationid());
                }
            }
        }
        
        if (!llaafnoap.isEmpty()) {
            for (int i = 0; i < llaafnoap.size(); i++) {
                String id = llaafnoap.get(i).getDocumentno();
                String borcode = llaafnoap.get(i).getBorrowers().getBorrowercode();
                String name = llaafnoap.get(i).getBorrowers().getCompletename();

                String info = id + " " + borcode + " " + name;
//                System.out.println(info);
                laapList1.add(info);
            }

            laapList = laapList1.toArray(new String[laapList1.size()]);
//            System.out.println(laapList);
        }

        laapList = laapList1.toArray(new String[laapList1.size()]);
        return SUCCESS;
    }
}
